﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;

namespace kTudu.Web.Extensions
{
    public static class MethodInfoExtensions
    {
        public static string GetMethodName(this MethodInfo mi)
        {
            string name = string.Empty;

            // busca si el metodo se encuentra dentro de un function<T>
            // lo que el mi.Name seria <Editar>___b19
            if (mi.Name.LastIndexOf('<') != -1)
                name = mi.Name.Substring(1, mi.Name.LastIndexOf('>') - 1);
            else
                name = mi.Name;

            return name;
        }

        public static string GetClassName(this MethodInfo mi)
        {
            string name = string.Empty;

            if (mi.DeclaringType.FullName.LastIndexOf('+') != -1)
            {
                string dynamicClassFullName = mi.DeclaringType.FullName;
                name = dynamicClassFullName.Substring(0, dynamicClassFullName.LastIndexOf('+'));
            }
            else
                name = mi.DeclaringType.FullName;

            return name;
        }
    }
}